﻿namespace KinonekoSoftware.Foundation.UI.Controls
{
#if AVALONIA
    
    using Avalonia.Controls.Metadata;
    using Control = Avalonia.Controls.Primitives.TemplatedControl;
    
    [PseudoClasses(":filled", ":stroke")]
    
#else
    
#endif
    
    public class Iconify : Control
    {
#if WINDOWS
        static Iconify()
        {
            DefaultStyleKeyProperty.OverrideMetadata(typeof(Iconify), new FrameworkPropertyMetadata(typeof(Iconify)));
            IconProperty = DependencyProperty.Register(
                nameof(Icon),
                typeof(Geometry),
                typeof(Iconify),
                new PropertyMetadata(default(Geometry)));
            IsFilledProperty = DependencyProperty.Register(
                nameof(IsFilled),
                typeof(bool),
                typeof(Iconify),
                new PropertyMetadata(default(bool)));
            IconSizeProperty = DependencyProperty.Register(
                nameof(IconSize),
                typeof(double),
                typeof(Iconify),
                new PropertyMetadata(default(double)));
            IconModeProperty = DependencyProperty.Register(
                nameof(IconMode),
                typeof(IconMode),
                typeof(Iconify),
                new PropertyMetadata(default(IconMode)));
            StrokeThicknessProperty = DependencyProperty.Register(
                nameof(StrokeThickness),
                typeof(int),
                typeof(Iconify),
                new PropertyMetadata(1));
        }


        public static readonly DependencyProperty IconProperty;
        public static readonly DependencyProperty IsFilledProperty;
        public static readonly DependencyProperty IconSizeProperty;
        public static readonly DependencyProperty IconModeProperty;
        public static readonly DependencyProperty StrokeThicknessProperty;

        private static void OnIIconSupportPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {

        }


        public IconMode IconMode
        {
            get => (IconMode)GetValue(IconModeProperty);
            set => SetValue(IconModeProperty, value);
        }

        public double IconSize
        {
            get => (double)GetValue(IconSizeProperty);
            set => SetValue(IconSizeProperty, value);
        }

        public bool IsFilled
        {
            get => (bool)GetValue(IsFilledProperty);
            set => SetValue(IsFilledProperty, Boxing.Box(value));
        }

        public Geometry Icon
        {
            get => (Geometry)GetValue(IconProperty);
            set => SetValue(IconProperty, value);
        }

        public int StrokeThickness
        {
            get => (int)GetValue(StrokeThicknessProperty);
            set => SetValue(StrokeThicknessProperty, value);
        }
#else
        public static readonly StyledProperty<Geometry> IconProperty;
        public static readonly StyledProperty<bool>     IsFilledProperty;
        public static readonly StyledProperty<int>      StrokeThicknessProperty;
        public static readonly StyledProperty<double>   IconSizeProperty;
        public static readonly StyledProperty<IconMode> IconModeProperty;

        static Iconify()
        {
            IconProperty            = AvaloniaProperty.Register<ForestButtonBase, Geometry>(nameof(Geometry));
            IsFilledProperty        = AvaloniaProperty.Register<ForestButtonBase, bool>(nameof(IsFilled));
            IconSizeProperty        = AvaloniaProperty.Register<ForestButtonBase, double>(nameof(IconSize));
            IconModeProperty        = AvaloniaProperty.Register<ForestButtonBase, IconMode>(nameof(IconMode));
            StrokeThicknessProperty = AvaloniaProperty.Register<ForestButtonBase, int>(nameof(StrokeThickness));

            IconProperty.Changed.Subscribe(OnIIconSupportPropertyChanged);
            IsFilledProperty.Changed.Subscribe(OnIIconSupportPropertyChanged);
            IconSizeProperty.Changed.Subscribe(OnIIconSupportPropertyChanged);
            IconModeProperty.Changed.Subscribe(OnIIconSupportPropertyChanged);
        }



        private static void OnIIconSupportPropertyChanged(AvaloniaPropertyChangedEventArgs e)
        {
            //
            // 重新绘制
        }


        public IconMode IconMode
        {
            get => GetValue(IconModeProperty);
            set => SetValue(IconModeProperty, value);
        }

        public double IconSize
        {
            get => GetValue(IconSizeProperty);
            set => SetValue(IconSizeProperty, value);
        }

        public bool IsFilled
        {
            get => GetValue(IsFilledProperty);
            set => SetValue(IsFilledProperty, value);
        }

        public Geometry Icon
        {
            get => GetValue(IconProperty);
            set => SetValue(IconProperty, value);
        }

        public int StrokeThickness
        {
            get => GetValue(StrokeThicknessProperty);
            set => SetValue(StrokeThicknessProperty, value);
        }
#endif
    }
}